package com.zkx.fssb.controller.server;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkx.fssb.domain.dto.UserDto;
import com.zkx.fssb.domain.vo.UserVo;
import com.zkx.fssb.result.Result;
import com.zkx.fssb.service.UserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("用户管理")
@Slf4j
@RestController("serverUserController")
@RequestMapping("/server/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录
     * @param UserDto
     * @return
     */
    @PostMapping("/login")
    public Result<UserVo> login(@RequestBody UserDto UserDto){
        log.info("userVo:{}",UserDto);
        UserVo userVo = userService.login(UserDto);

        return Result.success(userVo);

    }

    @GetMapping("/info")
    public Result<UserVo> getInfo(String token){
        UserVo userVo = new UserVo();

        return Result.success(userVo);

    }


    /**
     * 用户注册
     * @param UserDto
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody UserDto UserDto){
        log.info("用户注册,userVo:{}",UserDto);
        userService.register(UserDto);

        return Result.success("用户注册成功");

    }

    /**
     * 用户删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        userService.removeById(id);
        return Result.success("用户删除成功");
    }

    /**
     * 用户分页查询
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result<Page> page(Integer pageNo,Integer pageSize){

        Page pageInfo = new Page(pageNo,pageSize);
        userService.page(pageInfo);

        return Result.success(pageInfo);

    }


}
